home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / MacWT 0.04 / wt / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-31  |  1.7 KB  |  87 lines  |  [TEXT/MMCC]

  1. /*
  2. **  wt -- a 3d game engine
  3. **
  4. **  Copyright (C) 1994 by Chris Laurel
  5. **  email:  claurel@mr.net
  6. **  snail mail:  Chris Laurel, 5700 W Lake St #208,  St. Louis Park, MN  55416
  7. **
  8. **  This program is free software; you can redistribute it and/or modify
  9. **  it under the terms of the GNU General Public License as published by
  10. **  the Free Software Foundation; either version 2 of the License, or
  11. **  (at your option) any later version.
  12. **
  13. **  This program is distributed in the hope that it will be useful,
  14. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. **  GNU General Public License for more details.
  17. **
  18. **  You should have received a copy of the GNU General Public License
  19. **  along with this program; if not, write to the Free Software
  20. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22.  
  23. #include <stdlib.h>
  24. #include "wt.h"
  25. #include "wtmem.h"
  26. #include "list.h"
  27.  
  28.  
  29. List *new_list(void)
  30. {
  31.      List *l;
  32.  
  33.      l = wtmalloc(sizeof(List));
  34.      l->node = NULL;
  35.      l->next = NULL;
  36.  
  37.      return l;
  38. }
  39.  
  40.  
  41. void add_node(List *l, void *node)
  42. {
  43.      List *t;
  44.  
  45.      t = l->next;
  46.      l->next = new_list();
  47.      l->next->node = node;
  48.      l->next->next = t;
  49. }
  50.  
  51.  
  52. void delete_node(List *l)
  53. {
  54.      List *t;
  55.  
  56.      t = l->next->next;
  57.      if (l->next->node != NULL)
  58.       free(l->next->node);
  59.      wtfree(l->next);
  60.      l->next = t;
  61. }
  62.  
  63.  
  64. void delete_list(List *l)
  65. {
  66.      while (l->next)
  67.       delete_node(l);
  68.  
  69.      wtfree(l);
  70. }
  71.  
  72.  
  73. List *scan_list(List *l, void *data,
  74.         List_result (*scan_function)(void *node, void *data))
  75. {
  76.      List *t = l;
  77.  
  78.      while (t->next != NULL) {
  79.       if (scan_function(t->next->node, data) == List_success)
  80.            break;
  81.       else
  82.            t = t->next;
  83.      }
  84.  
  85.      return t;
  86. }
  87.